package zhzz;

import java.util.ArrayList;
import java.util.List;

import bingliandshuju.SingleDataofAll;

import com.example.animaldoctor03.AllIllness;
import com.example.animaldoctor03.BiaoGuanZhengZhuang;
import com.example.animaldoctor03.R;
import com.example.animaldoctor03.YiXuanZhengZhuang;

import Modle.disease.ClinicalSymptomsKey;
import Modle.disease.Symptoms;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ChoiceDetail extends Activity  {

	private SingleDataofzhzz singleDataofzhzzofCD = SingleDataofzhzz.getInstance();
	private SingleDataofAll singleDataofCDetail = SingleDataofAll.getInstance();
	
	private static int listofCDetail2length = 0 , listofCDetaillength = 0;
	private ListView listVofCDetail ;
	private Button btofCDetailtozd , btofCDetailforQC;
	private List<Integer> weizi = new ArrayList<Integer>();

	private List<Object> listofCDetail2 = singleDataofzhzzofCD.getListinformation();
	private List<Object> listofCDetail =  singleDataofCDetail.getListinformation();
	private List<Object> listofCDetail3 = new ArrayList<Object>();
	private void chushihuaofcd(){
		setContentView(R.layout.choicedetail);
		listVofCDetail = (ListView)findViewById(R.id.listofchoicedetail);
		btofCDetailtozd = (Button)findViewById(R.id.btofchoicedt1);
		btofCDetailforQC = (Button)findViewById(R.id.btofchoicedt2);
		
		btofCDetailtozd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ArrayList<Object> listofCD = new ArrayList<Object>();
				SingleDataofAll singledataofallofCD = SingleDataofAll.getInstance();
				listofCD = (ArrayList<Object>) singledataofallofCD.getListinformation();
			
				
				Bundle bundlleofCD = new Bundle();
				bundlleofCD.putSerializable("shuju", listofCD);
				Intent intentofCD = new Intent(ChoiceDetail.this , AllIllnessOfZH.class);
				intentofCD.putExtras(bundlleofCD);
				startActivity(intentofCD);
				finish();
				
			}
		});
		
		btofCDetailforQC.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				for(Integer a : weizi)
					{
					 	int i = a;

					if(i < listofCDetail2length  ){
						singleDataofzhzzofCD.removeZofListInformation(i);
					}
					else{
						
						i = i - listofCDetail2length;
						singleDataofCDetail.removeListZofInformation(i);
					}
					
				}
				Message msg = new Message();
				msg.what = 1;
				myHandler.sendMessage(msg);
		}
			
		});
	}
	private void getInformationofCDetail (){
		

		listofCDetail2length = listofCDetail2.size();
		
		
		listofCDetaillength = listofCDetail.size();
	}
	private void shezhiKJ(){
		try{
			getInformationofCDetail();
		
		List<String> listofAChoiceofXZ = new ArrayList<String>();
		

		for(int a = 0 ; a < listofCDetail2.size(); a++){
			
			Symptoms s = (Symptoms) listofCDetail2.get(a);
			listofAChoiceofXZ.add(s.getSymptomsName());
			
		}
		for(int i = 0 ; i < listofCDetail.size(); i ++ ){
			
			Symptoms ctextofBL3 = (Symptoms) listofCDetail.get(i);
			listofAChoiceofXZ.add(ctextofBL3.getSymptomsName());
			
		}
		String [] allchoice =  new String [listofAChoiceofXZ.size()];
		for(int i = 0 ; i < listofAChoiceofXZ.size() ; i++){
			
			allchoice[i] = listofAChoiceofXZ.get(i);
		}
		for(int j = 0 ; j < allchoice.length ; j++){
			
			System.out.print(allchoice[j]);
		}
		
		ArrayAdapter<String> arrayAdapter =  new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice ,allchoice);
 		
		listVofCDetail.setAdapter(arrayAdapter);
		listVofCDetail.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				weizi.clear();
				for(long ids :listVofCDetail.getCheckItemIds() ){
					
					int i = (int) ids;
					weizi.add(i);

				
			}
		}});

	
	
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofYXZZ = new AlertDialog.Builder(ChoiceDetail.this);
			builderofYXZZ.setMessage("没有数据,请选择其他功能");
			builderofYXZZ.create().show();
		}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		chushihuaofcd();
		getInformationofCDetail();
		 shezhiKJ();
		
	}

	Handler myHandler = new Handler() {

		public void handleMessage(Message msg) {
			if (msg.what == 1) {

				SingleDataofAll.setJishu(0);
				SingleDataofzhzz.setJishu(0);
				Intent intent = new Intent(ChoiceDetail.this,
						ChoiceDetail.class);
				startActivity(intent);
				finish();
			}

		}

	};
}
